import { CreateFloraReportParams, FloraQueryResult, FloraStatisticsItem, NameLaItem, ReportGenerateResult, ReportParagraphBlock, SpeciesInfo, TypeMergedRowData } from "./typings/index";
import { classifyOrganismV2, generateWordParagraBlockByPlainText, generateWordParagraBlockByTableGenerateResult, getChineseNumber, getProportionValue } from "./utils";


const filterFloraStatisticsItemList = (floraStatisticsItemList: FloraStatisticsItem[], speciesTypeList: string[]): FloraStatisticsItem[] => {
    let resultFloraStatisticsItemList: FloraStatisticsItem[] = JSON.parse(JSON.stringify(floraStatisticsItemList));
    resultFloraStatisticsItemList.forEach(floraStatisticsItem => {
        floraStatisticsItem.speciesNameUniquenList = floraStatisticsItem.speciesNameUniquenList.filter(row => {
            return row.speciesType && speciesTypeList.includes(row.speciesType);
        })
        floraStatisticsItem.genusNameUniquenList = floraStatisticsItem.genusNameUniquenList.filter(row => {
            return row.speciesType && speciesTypeList.includes(row.speciesType);
        })
        floraStatisticsItem.familyNameUniquenList = floraStatisticsItem.familyNameUniquenList.filter(row => {
            return row.speciesType && speciesTypeList.includes(row.speciesType);
        })
    })
    const result = resultFloraStatisticsItemList.filter(floraStatisticsItem => {
        return (floraStatisticsItem.speciesNameUniquenList.length !== 0 || floraStatisticsItem.genusNameUniquenList.length !== 0 || floraStatisticsItem.familyNameUniquenList.length !== 0)
    })
    return result;
}


//创建区系分析
// 一、首先植物区系分析
// 种子植物科的区系 (占比汇总描述、世界分布～中国特有分布共15 种描述)
// 种子植物属的区系 (占比汇总描述、世界分布~中国特有分布共15 种描述)
// 动物区系分析
const createFloraReport = (params: CreateFloraReportParams): ReportGenerateResult => {
    let reportGenerateResult: ReportGenerateResult = {
        reportParagraphList: [],
        matchFailureParagraphList: []
    }
    try {
        let reportParagraphList: ReportParagraphBlock[] = [];
        let matchFailureParagraphList: ReportParagraphBlock[] = [];
        const {
            mergedRowDataList,
            floraQueryResult,
            type,
        } = params;
        if (type == 'analys') {
            reportParagraphList.push(generateWordParagraBlockByPlainText('区系分析', 'heading1', false))
        } else {
            reportParagraphList.push(generateWordParagraBlockByPlainText('区系分析报告', 'heading1', false))
        }
        let mergedRowDataListWidthSpeciesInfo: SpeciesInfo[] = [];
        const {
            speciesList,
            genusList,
            familyList
        } = floraQueryResult;
        mergedRowDataList.forEach(row => {
            const speciesType = classifyOrganismV2(row);
            if (row.canorical_me && !['其他植物', '其他脊索动物', '其他动物', '未知'].includes(speciesType)) {
                //匹配区系状态
                const findSpeciesFlora = speciesList.find(ele => {
                    return ele.type == 'species' && ele.speciesName === row.speciesName;
                })
                const findGenusFlora = genusList.find(ele => {
                    return ele.type == 'genus' && ele.genusLa === row.genus;
                })
                const findFamilyFlora = familyList.find(ele => {
                    return ele.type == 'family' && ele.familyLa === row.family;
                })
                row.speciesFlora = findSpeciesFlora;
                row.genusFlora = findGenusFlora;
                row.familyFlora = findFamilyFlora;
                row.speciesType = speciesType;
                mergedRowDataListWidthSpeciesInfo.push(row)
            }
        })
        console.log("mergedRowDataListWidthSpeciesInfo---->", mergedRowDataListWidthSpeciesInfo)
        const floraStatisticsItemList: FloraStatisticsItem[] = [];
        mergedRowDataListWidthSpeciesInfo.forEach(mergedRow => {
            if (mergedRow.speciesFlora && mergedRow.speciesFlora.flora) {
                let findFloraStatisticsItemBySpeciesIndex = -1;
                floraStatisticsItemList.forEach((item, index) => {
                    if (mergedRow.speciesFlora && item.floraName === mergedRow.speciesFlora.flora) {
                        findFloraStatisticsItemBySpeciesIndex = index;
                    }
                })
                if (findFloraStatisticsItemBySpeciesIndex > -1) {
                    let _speciesNameUniquenList: NameLaItem[] = floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].speciesNameUniquenList;
                    floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].times++;
                    let findSpeciesNameIndex = -1;
                    _speciesNameUniquenList.forEach((ele, index) => {
                        if (ele.nameZH == mergedRow.speciesName) {
                            findSpeciesNameIndex = index;
                        }
                    })
                    if (findSpeciesNameIndex == -1) {
                        _speciesNameUniquenList.push({
                            nameLA: mergedRow.canorical_me,
                            nameZH: mergedRow.speciesName,
                            speciesType: mergedRow.speciesType,
                        })
                    }
                    floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].speciesNameUniquenList = _speciesNameUniquenList;
                } else {
                    floraStatisticsItemList.push({
                        floraName: mergedRow.speciesFlora.flora,
                        floraItem: mergedRow.speciesFlora,
                        speciesNameUniquenList: [{
                            //@ts-ignore
                            nameLA: mergedRow.canorical_me,
                            nameZH: mergedRow.speciesName,
                            speciesType: mergedRow.speciesType,
                        }],
                        genusNameUniquenList: [],
                        familyNameUniquenList: [],
                        times: 1
                    })
                }
            }
            //被子植物属
            if (mergedRow.genusFlora && mergedRow.genusFlora.flora) {
                let findFloraStatisticsItemBySpeciesIndex = -1;
                floraStatisticsItemList.forEach((item, index) => {
                    if (mergedRow.genusFlora && item.floraName === mergedRow.genusFlora.flora) {
                        findFloraStatisticsItemBySpeciesIndex = index;
                    }
                })
                if (findFloraStatisticsItemBySpeciesIndex > -1) {
                    let _genusNameUniquenList: NameLaItem[] = floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].genusNameUniquenList;
                    floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].times++;
                    let findSpeciesNameIndex = -1;
                    _genusNameUniquenList.forEach((ele, index) => {
                        if (ele.nameZH == mergedRow.speciesName) {
                            findSpeciesNameIndex = index;
                        }
                    })
                    if (findSpeciesNameIndex == -1) {
                        _genusNameUniquenList.push({
                            nameLA: mergedRow.canorical_me,
                            nameZH: mergedRow.speciesName,
                            speciesType: mergedRow.speciesType,
                        })
                    }
                    floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].genusNameUniquenList = _genusNameUniquenList;
                } else {
                    floraStatisticsItemList.push({
                        floraName: mergedRow.genusFlora.flora,
                        floraItem: mergedRow.genusFlora,
                        speciesNameUniquenList: [],
                        genusNameUniquenList: [{
                            //@ts-ignore
                            nameLA: mergedRow.canorical_me,
                            nameZH: mergedRow.speciesName,
                            speciesType: mergedRow.speciesType,
                        }],
                        familyNameUniquenList: [],
                        times: 1
                    })
                }
            }
            //世界植物科
            if (mergedRow.familyFlora && mergedRow.familyFlora.flora) {
                let findFloraStatisticsItemBySpeciesIndex = -1;
                floraStatisticsItemList.forEach((item, index) => {
                    if (mergedRow.familyFlora && item.floraName === mergedRow.familyFlora.flora) {
                        findFloraStatisticsItemBySpeciesIndex = index;
                    }
                })
                if (findFloraStatisticsItemBySpeciesIndex > -1) {
                    let _familyNameUniquenList: NameLaItem[] = floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].familyNameUniquenList;
                    floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].times++;
                    let findSpeciesNameIndex = -1;
                    _familyNameUniquenList.forEach((ele, index) => {
                        if (ele.nameZH == mergedRow.speciesName) {
                            findSpeciesNameIndex = index;
                        }
                    })
                    if (findSpeciesNameIndex == -1) {
                        _familyNameUniquenList.push({
                            nameLA: mergedRow.canorical_me,
                            nameZH: mergedRow.speciesName,
                            speciesType: mergedRow.speciesType,
                        })
                    }
                    floraStatisticsItemList[findFloraStatisticsItemBySpeciesIndex].familyNameUniquenList = _familyNameUniquenList;
                } else {
                    floraStatisticsItemList.push({
                        floraName: mergedRow.familyFlora.flora,
                        floraItem: mergedRow.familyFlora,
                        speciesNameUniquenList: [],
                        genusNameUniquenList: [],
                        familyNameUniquenList: [{
                            //@ts-ignore
                            nameLA: mergedRow.canorical_me,
                            nameZH: mergedRow.speciesName,
                            speciesType: mergedRow.speciesType,
                        }],
                        times: 1
                    })
                }
            }
        })
        console.log("floraStatisticsItemList---->", floraStatisticsItemList)
        let serialNumber1 = 1;
        let serialNumber2 = 1;
        let tableSerialNumber = 1;
        //种子植物的区系
        let zhongziPlantFloraStatisticsItemList = filterFloraStatisticsItemList(floraStatisticsItemList, ['被子植物', '裸子植物']);
        //哺乳动物的区系
        let mammalFloraStatisticsItemList = filterFloraStatisticsItemList(floraStatisticsItemList, ['兽类']);
        //鸟类的区系
        let birdFloraStatisticsItemList = filterFloraStatisticsItemList(floraStatisticsItemList, ['鸟类']);
        //两爬类的区系
        let reptileFloraStatisticsItemList = filterFloraStatisticsItemList(floraStatisticsItemList, ['两爬类']);
        console.log("zhongziPlantFloraStatisticsItemList----->", zhongziPlantFloraStatisticsItemList);
        console.log("mammalFloraStatisticsItemList----->", mammalFloraStatisticsItemList);
        console.log("birdFloraStatisticsItemList----->", birdFloraStatisticsItemList);
        console.log("reptileFloraStatisticsItemList----->", reptileFloraStatisticsItemList);
        let zhongziPlantFloraStatisticsItemListByFamily = zhongziPlantFloraStatisticsItemList.filter(item => {
            return item.familyNameUniquenList.length > 0;
        })
        let zhongziPlantFloraStatisticsItemListByGenus = zhongziPlantFloraStatisticsItemList.filter(item => {
            return item.genusNameUniquenList.length > 0;
        })
        if (zhongziPlantFloraStatisticsItemList.length) {
            reportParagraphList.push(generateWordParagraBlockByPlainText(`${getChineseNumber(serialNumber1)}、植物区系分析`, 'heading3'));
            //种子植物科的区系
            if (zhongziPlantFloraStatisticsItemListByFamily.length) {
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumber1}.${serialNumber2} 种子植物科的区系`, 'heading3'));
                //泛热带分布类型的科有32科，占总数的42.67%，北温带分布类型的科有20科，占总数的26.67%，热带亚洲和热带美洲间断分布类型的科有7科，占总数的9.33%。分述如下：
                let zhongziPlantFloraTotalDescParagraphText = `种子植物科的区系中共有${zhongziPlantFloraStatisticsItemListByFamily.length}个地理成分，其中`;
                let totalFamilyCount = 0;
                zhongziPlantFloraStatisticsItemListByFamily.forEach((floraStatisticsItem, index) => {
                    totalFamilyCount += floraStatisticsItem.familyNameUniquenList.length;
                })
                zhongziPlantFloraStatisticsItemListByFamily.forEach((floraStatisticsItem, index) => {
                    zhongziPlantFloraTotalDescParagraphText += `${floraStatisticsItem.floraName}的科有${floraStatisticsItem.familyNameUniquenList.length}科，占总数的${getProportionValue(floraStatisticsItem.familyNameUniquenList.length, totalFamilyCount)}%`
                    if (index < zhongziPlantFloraStatisticsItemListByFamily.length - 1) {
                        zhongziPlantFloraTotalDescParagraphText += '，'
                    } else {
                        zhongziPlantFloraTotalDescParagraphText += '。分述如下：'
                    }
                })
                reportParagraphList.push(generateWordParagraBlockByPlainText(zhongziPlantFloraTotalDescParagraphText, 'normalParagraph'));
                let tableData: string[][] = [["区系类型", "包含科数", "百分比%"]];
                zhongziPlantFloraStatisticsItemListByFamily.forEach((floraStatisticsItem, index) => {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`(${index + 1}) ${floraStatisticsItem.floraName}`, 'normalParagraph'));
                    let floraItemDescParagraphText = `${floraStatisticsItem.floraName}共${floraStatisticsItem.familyNameUniquenList.length}科，它们是：`;
                    let proportionValue = getProportionValue(floraStatisticsItem.familyNameUniquenList.length, totalFamilyCount);
                    tableData.push([floraStatisticsItem.floraName, floraStatisticsItem.familyNameUniquenList.length + '', proportionValue + ''])
                    floraStatisticsItem.familyNameUniquenList.forEach((ele, index) => {
                        floraItemDescParagraphText += `${ele.nameZH}（${ele.nameLA}）`;
                        if (index < floraStatisticsItem.familyNameUniquenList.length - 1) {
                            floraItemDescParagraphText += `、`;
                        } else {
                            floraItemDescParagraphText += `。`;
                        }
                    })
                    reportParagraphList.push(generateWordParagraBlockByPlainText(floraItemDescParagraphText, 'normalParagraph'))
                })
                tableData.push(["合计", totalFamilyCount + '', '100%'])
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表${tableSerialNumber} 植物科分布区系统计表`, 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult({
                    tableStyle: 'normalTable',
                    tableData: tableData
                }))
                serialNumber2++;
                tableSerialNumber++;
            }
            //种子植物属的区系
            if (zhongziPlantFloraStatisticsItemListByGenus.length) {
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumber1}.${serialNumber2} 种子植物属的区系`, 'heading3'));
                //种子植物属的区系中共有13个地理成分，其中北温带分布类型的属有27属，占总数的17.88%，泛热带分布类型的属有26属，占总数的17.22%，热带亚洲分布类型的属有26属，占总数的17.22%。分述如下：
                let zhongziPlantFloraTotalDescParagraphText = `种子植物属的区系中共有${zhongziPlantFloraStatisticsItemListByGenus.length}个地理成分，其中`;
                let totalGenusCount = 0;
                zhongziPlantFloraStatisticsItemListByGenus.forEach((floraStatisticsItem, index) => {
                    totalGenusCount += floraStatisticsItem.genusNameUniquenList.length;
                })
                zhongziPlantFloraStatisticsItemListByGenus.forEach((floraStatisticsItem, index) => {
                    zhongziPlantFloraTotalDescParagraphText += `${floraStatisticsItem.floraName}类型的有${floraStatisticsItem.genusNameUniquenList.length}属，占总数的${getProportionValue(floraStatisticsItem.familyNameUniquenList.length, totalGenusCount)}%`
                    if (index < zhongziPlantFloraStatisticsItemListByGenus.length - 1) {
                        zhongziPlantFloraTotalDescParagraphText += '，'
                    } else {
                        zhongziPlantFloraTotalDescParagraphText += '。分述如下：'
                    }
                })
                reportParagraphList.push(generateWordParagraBlockByPlainText(zhongziPlantFloraTotalDescParagraphText, 'normalParagraph'));
                let tableData: string[][] = [["区系类型", "包含属数", "百分比%"]];
                zhongziPlantFloraStatisticsItemListByGenus.forEach((floraStatisticsItem, index) => {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`(${index + 1}) ${floraStatisticsItem.floraName}`, 'normalParagraph'));
                    let floraItemDescParagraphText = `${floraStatisticsItem.floraName}共${floraStatisticsItem.genusNameUniquenList.length}属，它们是：`;
                    let proportionValue = getProportionValue(floraStatisticsItem.genusNameUniquenList.length, totalGenusCount);
                    tableData.push([floraStatisticsItem.floraName, floraStatisticsItem.genusNameUniquenList.length + '', proportionValue + ''])
                    floraStatisticsItem.genusNameUniquenList.forEach((ele, index) => {
                        floraItemDescParagraphText += `${ele.nameZH}（${ele.nameLA}）`;
                        if (index < floraStatisticsItem.genusNameUniquenList.length - 1) {
                            floraItemDescParagraphText += `、`;
                        } else {
                            floraItemDescParagraphText += `。`;
                        }
                    })
                    reportParagraphList.push(generateWordParagraBlockByPlainText(floraItemDescParagraphText, 'normalParagraph'))
                })
                tableData.push(["合计", totalGenusCount + '', '100%'])
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表${tableSerialNumber} 植物属分布区系统计表`, 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult({
                    tableStyle: 'normalTable',
                    tableData: tableData
                }))
                serialNumber2++;
                tableSerialNumber++;
            }
            serialNumber1++;
        }
        //动物区系分析
        if (
            mammalFloraStatisticsItemList.length ||
            birdFloraStatisticsItemList.length ||
            reptileFloraStatisticsItemList.length
        ) {
            serialNumber2 = 1;
            reportParagraphList.push(generateWordParagraBlockByPlainText(`${getChineseNumber(serialNumber1)}、动物区系分析`, 'heading3'));
            let animalFirstParagraph = `据本次调查，涉及调查区域共有`;
            let mammalFloraStatisticsTable: string[][] = [["分布区系类型", "种数", "占总种数的百分比%"]];
            let birdFloraStatisticsTable: string[][] = [["分布区系类型", "种数", "占总种数的百分比%"]];
            let reptileFloraStatisticsTable: string[][] = [["分布区系类型", "种数", "占总种数的百分比%"]];
            //如果有哺乳类
            let mammalTotalSpeciesCount = 0;
            if (mammalFloraStatisticsItemList.length) {
                mammalFloraStatisticsItemList.forEach(floraStatisticsItem => {
                    mammalTotalSpeciesCount += floraStatisticsItem.speciesNameUniquenList.length;
                })
                //古北型的物种有11种，占总数的5.95%；东洋型的物种有89种，占总数的48.11%；全北型的物种有5种，占总数的2.70%；中亚型的物种有1种，占总数的0.54%；季风区型的物种有7种，占总数的3.78%；喜马拉雅-横断山区型的物种有31种，占总数的16.76%；东北型的物种有1种，占总数的0.54%；高地型的物种有9种，占总数的4.86%；南中国型的物种有25种，占总数的13.51%；东北-华北型的物种有1种，占总数的0.54%；不易归类的物种有5种，占总数的2.70%；
                let mammalTotalDescParagraphText = `哺乳动物${mammalTotalSpeciesCount}个种，在种的区系中共有${mammalFloraStatisticsItemList.length}个地理成分，其中`;
                animalFirstParagraph += mammalTotalDescParagraphText;
                //生成统计段落 + 组装表格内容
                mammalFloraStatisticsItemList.forEach(floraStatisticsItem => {
                    let proportionValue = getProportionValue(floraStatisticsItem.genusNameUniquenList.length, mammalTotalSpeciesCount);
                    mammalFloraStatisticsTable.push([floraStatisticsItem.floraName, floraStatisticsItem.speciesNameUniquenList.length + '', proportionValue + ''])
                    mammalTotalDescParagraphText += `${floraStatisticsItem.floraName}的物种有${floraStatisticsItem.speciesNameUniquenList.length}种，占总数的${proportionValue}%`
                })
                mammalFloraStatisticsTable.push(["合计", mammalTotalSpeciesCount + '', '100%'])
                reportParagraphList.push(generateWordParagraBlockByPlainText(animalFirstParagraph, 'normalParagraph'));
            }
            //如果有鸟类
            let birdTotalSpeciesCount = 0;
            if (birdFloraStatisticsItemList.length) {
                birdFloraStatisticsItemList.forEach(floraStatisticsItem => {
                    birdTotalSpeciesCount += floraStatisticsItem.speciesNameUniquenList.length;
                })
                //古北型的物种有11种，占总数的5.95%；东洋型的物种有89种，占总数的48.11%；全北型的物种有5种，占总数的2.70%；中亚型的物种有1种，占总数的0.54%；季风区型的物种有7种，占总数的3.78%；喜马拉雅-横断山区型的物种有31种，占总数的16.76%；东北型的物种有1种，占总数的0.54%；高地型的物种有9种，占总数的4.86%；南中国型的物种有25种，占总数的13.51%；东北-华北型的物种有1种，占总数的0.54%；不易归类的物种有5种，占总数的2.70%；
                let birdTotalDescParagraphText = `鸟类${birdTotalSpeciesCount}个种，在种的区系中共有${birdFloraStatisticsItemList.length}个地理成分，其中`;
                //生成统计段落 + 组装表格内容
                birdFloraStatisticsItemList.forEach(floraStatisticsItem => {
                    let proportionValue = getProportionValue(floraStatisticsItem.genusNameUniquenList.length, birdTotalSpeciesCount);
                    birdFloraStatisticsTable.push([floraStatisticsItem.floraName, floraStatisticsItem.speciesNameUniquenList.length + '', proportionValue + ''])
                    birdTotalDescParagraphText += `${floraStatisticsItem.floraName}的物种有${floraStatisticsItem.speciesNameUniquenList.length}种，占总数的${proportionValue}%`
                })
                birdFloraStatisticsTable.push(["合计", birdTotalSpeciesCount + '', '100%'])
                if (mammalFloraStatisticsItemList.length == 0) {
                    animalFirstParagraph += birdTotalDescParagraphText;
                    reportParagraphList.push(generateWordParagraBlockByPlainText(animalFirstParagraph, 'normalParagraph'));
                } else {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(birdTotalDescParagraphText, 'normalParagraph'));
                }
            }
            //如果有两爬类
            let reptileTotalSpeciesCount = 0;
            if (reptileFloraStatisticsItemList.length) {
                reptileFloraStatisticsItemList.forEach(floraStatisticsItem => {
                    reptileTotalSpeciesCount += floraStatisticsItem.speciesNameUniquenList.length;
                })
                //古北型的物种有11种，占总数的5.95%；东洋型的物种有89种，占总数的48.11%；全北型的物种有5种，占总数的2.70%；中亚型的物种有1种，占总数的0.54%；季风区型的物种有7种，占总数的3.78%；喜马拉雅-横断山区型的物种有31种，占总数的16.76%；东北型的物种有1种，占总数的0.54%；高地型的物种有9种，占总数的4.86%；南中国型的物种有25种，占总数的13.51%；东北-华北型的物种有1种，占总数的0.54%；不易归类的物种有5种，占总数的2.70%；
                let reptileTotalDescParagraphText = `两爬类动物${reptileTotalSpeciesCount}个种，在种的区系中共有${reptileFloraStatisticsItemList.length}个地理成分，其中`;
                //生成统计段落 + 组装表格内容
                reptileFloraStatisticsItemList.forEach(floraStatisticsItem => {
                    let proportionValue = getProportionValue(floraStatisticsItem.genusNameUniquenList.length, reptileTotalSpeciesCount);
                    reptileFloraStatisticsTable.push([floraStatisticsItem.floraName, floraStatisticsItem.speciesNameUniquenList.length + '', proportionValue + ''])
                    reptileTotalDescParagraphText += `${floraStatisticsItem.floraName}的物种有${floraStatisticsItem.speciesNameUniquenList.length}种，占总数的${proportionValue}%`
                })
                reptileFloraStatisticsTable.push(["合计", reptileTotalSpeciesCount + '', '100%'])
                if (reptileFloraStatisticsItemList.length == 0) {
                    animalFirstParagraph += reptileTotalDescParagraphText;
                    reportParagraphList.push(generateWordParagraBlockByPlainText(animalFirstParagraph, 'normalParagraph'));
                } else {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(reptileTotalDescParagraphText, 'normalParagraph'));
                }
            }
            if (mammalFloraStatisticsItemList.length) {
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumber2}. 哺乳动物区系分析`, 'normalParagraph'));
                mammalFloraStatisticsItemList.forEach((floraStatisticsItem, index) => {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`(${index + 1}) ${floraStatisticsItem.floraName}`, 'normalParagraph'));
                    // 古北型共11种，占总种数的5.95%，它们是：野猪（Sus scrofa）、小家鼠（Mus musculus）、水獭（Lutra lutra）、石貂（Martes foi）、麝鼠（Ondatra zibethicus）、黄鼬（Mustela sibirica）、黑线姬鼠（Apodemus agrarius）、褐家鼠（Rattus norvegicus）、大棕蝠（Eptesicus serotinus）、灰喜鹊（Cyanopica cyanus subsp. stegmanni）、松鼠（Sciurus vulgaris）。
                    let floraSpeciesDescParagraphText = `${floraStatisticsItem.floraName}共${floraStatisticsItem.speciesNameUniquenList.length}种，占总种数的${getProportionValue(floraStatisticsItem.speciesNameUniquenList.length, mammalTotalSpeciesCount)}%，它们是：`;
                    floraStatisticsItem.speciesNameUniquenList.forEach((ele, index) => {
                        floraSpeciesDescParagraphText += `${ele.nameZH}（${ele.nameLA}）`;
                        if (floraStatisticsItem.speciesNameUniquenList.length - 1 > index) {
                            floraSpeciesDescParagraphText += '、';
                        } else {
                            floraSpeciesDescParagraphText += '。';
                        }
                    })
                    reportParagraphList.push(generateWordParagraBlockByPlainText(floraSpeciesDescParagraphText, 'normalParagraph'));
                })
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表${tableSerialNumber}哺乳动物分布区系统计表`, 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult({
                    tableStyle: 'normalTable',
                    tableData: mammalFloraStatisticsTable
                }));
                serialNumber2++;
                tableSerialNumber++;
            }
            if (birdFloraStatisticsItemList.length) {
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumber2}. 鸟类区系分析`, 'normalParagraph'));
                birdFloraStatisticsItemList.forEach((floraStatisticsItem, index) => {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`(${index + 1}) ${floraStatisticsItem.floraName}`, 'normalParagraph'));
                    let floraSpeciesDescParagraphText = `${floraStatisticsItem.floraName}共${floraStatisticsItem.speciesNameUniquenList.length}种，占总种数的${getProportionValue(floraStatisticsItem.speciesNameUniquenList.length, mammalTotalSpeciesCount)}%，它们是：`;
                    floraStatisticsItem.speciesNameUniquenList.forEach((ele, index) => {
                        floraSpeciesDescParagraphText += `${ele.nameZH}（${ele.nameLA}）`;
                        if (floraStatisticsItem.speciesNameUniquenList.length - 1 > index) {
                            floraSpeciesDescParagraphText += '、';
                        } else {
                            floraSpeciesDescParagraphText += '。';
                        }
                    })
                    reportParagraphList.push(generateWordParagraBlockByPlainText(floraSpeciesDescParagraphText, 'normalParagraph'));
                })
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表${tableSerialNumber}鸟类分布区系统计表`, 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult({
                    tableStyle: 'normalTable',
                    tableData: birdFloraStatisticsTable
                }));
                serialNumber2++;
                tableSerialNumber++;
            }
            if (reptileFloraStatisticsItemList.length) {
                reportParagraphList.push(generateWordParagraBlockByPlainText(`${serialNumber2}. 两爬类动物区系分析`, 'normalParagraph'));
                reptileFloraStatisticsItemList.forEach((floraStatisticsItem, index) => {
                    reportParagraphList.push(generateWordParagraBlockByPlainText(`(${index + 1}) ${floraStatisticsItem.floraName}`, 'normalParagraph'));
                    let floraSpeciesDescParagraphText = `${floraStatisticsItem.floraName}共${floraStatisticsItem.speciesNameUniquenList.length}种，占总种数的${getProportionValue(floraStatisticsItem.speciesNameUniquenList.length, mammalTotalSpeciesCount)}%，它们是：`;
                    floraStatisticsItem.speciesNameUniquenList.forEach((ele, index) => {
                        floraSpeciesDescParagraphText += `${ele.nameZH}（${ele.nameLA}）`;
                        if (floraStatisticsItem.speciesNameUniquenList.length - 1 > index) {
                            floraSpeciesDescParagraphText += '、';
                        } else {
                            floraSpeciesDescParagraphText += '。';
                        }
                    })
                    reportParagraphList.push(generateWordParagraBlockByPlainText(floraSpeciesDescParagraphText, 'normalParagraph'));
                })
                reportParagraphList.push(generateWordParagraBlockByPlainText(`表${tableSerialNumber}两爬类动物分布区系统计表`, 'smallTableName'));
                reportParagraphList.push(generateWordParagraBlockByTableGenerateResult({
                    tableStyle: 'normalTable',
                    tableData: reptileFloraStatisticsTable
                }));
            }
        }
        console.log("reportParagraphList--->", reportParagraphList);
        if (type == 'analys') {
            reportParagraphList = reportParagraphList.filter(paragraph => {
                return paragraph.paragraphType == 'heading1' || paragraph.paragraphType == 'smallTableName' || paragraph.type == 'Table';
            })
        }
        reportGenerateResult.reportParagraphList = reportParagraphList;
        return reportGenerateResult;
    } catch (e) {
        console.log("生成区系失败", e)
        return reportGenerateResult;
    }
}

export default createFloraReport;